package com.lz.yz.member.service.impl;

import com.lz.yz.base.entity.ReturnValue;
import com.lz.yz.core.AbstractService;
import com.lz.yz.member.dao.FeedbackMapper;
import com.lz.yz.member.entity.Feedback;
import com.lz.yz.member.model.FeedbackModel;
import com.lz.yz.member.service.FeedbackService;
import com.lz.yz.outing.service.SyncLockService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;


@Service
@Transactional
public class FeedbackServiceImpl extends AbstractService<Feedback> implements FeedbackService {

    @Resource
    private FeedbackMapper feedbackMapper;

    @Autowired
    SyncLockService syncLockService;

    @Override
    public ReturnValue add(Integer accountId, FeedbackModel feedbackModel) {
        if (!syncLockService.syncLock("addFeedback/" + accountId, 5, TimeUnit.SECONDS)) {
            return ReturnValue.generateFalseReturnValue("请不要重复提交!");
        }
        Feedback feedback=new Feedback();
        BeanUtils.copyProperties(feedbackModel,feedback);
        feedback.setOpinionAccountId(accountId);
        feedbackMapper.insertSelective(feedback);
       return  ReturnValue.generateTrueMsgReturnValue("提交成功");
    }
}
